/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import Controller.MyLinkList;
import entities.Book;
import java.util.Scanner;

/**
 *
 * @author Chup Chep
 */
public class Main {

    public static void main(String[] args) {
        MyLinkList mdll = new MyLinkList();
        Scanner sn = new Scanner(System.in);
        int choose1;
        do {
            Menu();
            choose1 = sn.nextInt();
            switch (choose1) {
                case 1:
                    while (true) {
                        menuBook();
                        int choose;
                        choose = sn.nextInt();
                        switch (choose) {
                            case 1:
                                mdll.readFile();
                                mdll.displayBook();
                                break;
                            case 2:
                                while (true) {
                                    mdll.addBookLast(inputBook());
                                    System.out.println("Do you want to input continutes (y/n)? ");
                                    String input = sn.next();
                                    if (input.equals("n")) {
                                        break;
                                    }
                                }
                                break;
                            case 3:
                                System.out.println("=========================Book Management=======================================");
                                System.out.println(" Code  |      Title     |    Quantity      |  Lended  |    Price   |   Value  |");
                                mdll.displayBook();
                                System.out.println("-----------------------------------the end-------------------------------------");
                                break;
                            case 4:
                                mdll.saveFile();
                                break;
                            case 5:
                                System.out.println("Enter Book Code search : ");
                                String code = sn.next();
                                System.out.println("=========================Book Management===========================");
                                System.out.println(" Code  |      Title     |    Quantity      |  Lended  |    Price   |");
                                System.out.printf("%-11s %-16s %-15s %-13s %s", mdll.bookSearch(code).info.getBcode(),
                                        mdll.bookSearch(code).info.getTitle(), mdll.bookSearch(code).info.getQuantity(),
                                        mdll.bookSearch(code).info.getLended(), mdll.bookSearch(code).info.getPrice() + "\n");
                                System.out.println("------------------------------the end------------------------------");
                                break;
                            case 6:
                                System.out.println("Enter Book Code delete : ");
                                String code1 = sn.next();
                                mdll.bookDelete(code1);
                                break;
                            case 7:
                                mdll.sort();
                                break;
                            case 8:
                                while (true) {
                                    mdll.addBookFirst(inputBook());
                                    System.out.println("Do you want to input continutes (y/n)? ");
                                    String input = sn.next();
                                    if (input.equals("n")) {
                                        break;
                                    }
                                }
                                break;
                            case 9:
                                while (true) {
                                    System.out.println("Enter positon book code : ");
                                    String code2 = sn.next();
                                    mdll.insertAfterNodeBook(inputBook(), code2);
                                    System.out.println("Do you want to input continutes (y/n)? ");
                                    String input = sn.next();
                                    if (input.equals("n")) {
                                        break;
                                    }
                                }
                                break;
                            case 10:
                                break;
                        }
                        if (choose == 0) {
                            break;
                        }
                    }
                    break;
                case 2:
                    while (true) {
                        menuReader();
                        int choose2;
                        choose2 = sn.nextInt();
                        switch (choose2) {
                            case 1:
                                break;
                            case 2:
                                break;
                            case 3:
                                break;
                            case 4:
                                break;
                            case 5:
                                break;
                            case 6:
                                break;
                        }
                        if (choose2 == 0) {
                            break;
                        }
                    }
                    break;
                case 3:
                    while (true) {
                        menuLending();
                        int choose3;
                        choose3 = sn.nextInt();
                        switch (choose3) {
                            case 1:
                                break;
                            case 2:
                                break;
                            case 3:
                                break;
                        }
                        if (choose3 == 0) {
                            break;
                        }
                    }
                    break;
            }
        } while (choose1 > 0 && choose1 < 4);
    }

    public static void Menu() {
        System.out.println("---------Menu----------");
        System.out.println("1. Book management.");
        System.out.println("2. Reader management.");
        System.out.println("3. Lending management.");
        System.out.println("0. Exit");
        System.out.println("Your selection (0 -> 3):");
    }

    public static void menuBook() {
        System.out.println("-------Menu Book-------");
        System.out.println("1. Load data form file");
        System.out.println("2. Input & add to end");
        System.out.println("3. Display data");
        System.out.println("4. Save data to file");
        System.out.println("5. Search by code");
        System.out.println("6. Delete by code");
        System.out.println("7. Sort by code");
        System.out.println("8. Input & add to beginning");
        System.out.println("9. Add after postition k");
        System.out.println("10. Delete position k");
        System.out.println("0. Back");
        System.out.println("Your selection (0 -> 10)");
    }

    public static void menuReader() {
        System.out.println("--------Menu Reader-------");
        System.out.println("1. Load data form file");
        System.out.println("2. Input & add to end");
        System.out.println("3. Display data");
        System.out.println("4. Save data to file");
        System.out.println("5. Search by rcode");
        System.out.println("6. Delete by rcode");
        System.out.println("0. Back");
        System.out.println("Your selection (0 -> 6):");
    }

    public static void menuLending() {
        System.out.println("-------Menu Lending-------");
        System.out.println("1. Input data.");
        System.out.println("2. Display data.");
        System.out.println("3. Sort by bcode + rcode.");
        System.out.println("0. Back");
        System.out.println("Your selection (0 -> 3):");
    }

    public static Book inputBook() {
        Scanner sn = new Scanner(System.in);
        System.out.println("Enter Book code : ");
        String code = sn.next();
        System.out.println("Enter Book title : ");
        sn.nextLine();
        String title = sn.nextLine();
        System.out.println("Enter Book quantity : ");
        int quantity = sn.nextInt();
        System.out.println("Enter Book lended : ");
        int lended = sn.nextInt();
        System.out.println("Enter Book price : ");
        double price = sn.nextDouble();
        return new Book(code, title, quantity, lended, price);
    }
}
